define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'appindex/index',
                    add_url: 'appindex/add',
                    edit_url: 'appindex/edit',
                    del_url: 'appindex/del',
                    multi_url: 'appindex/multi',
                    table: 'app_index',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search: false,
                searchFormVisible: true,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'adposition.name', title: __('Position'), operate:false},
                        {field: 'position', title: __('Position'),searchList: $.getJSON('base/getPositions'), visible:false},
                        {field: 'app_image', title: __('App_image'), formatter: Table.api.formatter.image, operate:false},
                        // {field: 'name', title: __('Name')},
                        {field: 'param_id', title: __('Param_id')},
                        // {field: 'login', title: __('Login'), visible:false, searchList: {"1":__('Login 1')}},
                        // {field: 'login_text', title: __('Login'), operate:false},
                        // {field: 'cname.name', title: __('App_class_id'), operate:false},
                        // {field: 'app_class_id', title: __('App_class_id'), visible:false, searchList: $.getJSON('base/getAppclass')},
                        {field: 'sort', title: __('Sort'), operate:false, sortable:true},
                        {field: 'begin_time', title: __('Begin_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'end_time', title: __('End_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});